<template>
  <view class="main">
    <view class="box">
      <view class="title">提现积分</view>
      <up-input v-model="formData.amount" type="number" class="input_num" fontSize="40rpx" color="#FFF" placeholder="请输入数量" border="none" clearable>
        <template #suffix>
          <text class="all_text" @click="allClick">全部提现</text>
        </template>
      </up-input>
      <view class="des">
        <view>
          可提现金额:
          <text>{{ banlanceAmont }}</text>
        </view>
        <view>手续费：3%</view>
      </view>
    </view>
    <view>
      <view class="payBox">
        <view>提现至</view>
        <radio-group @change="radioChange">
          <!-- <label class="uni-list-cell uni-list-cell-pd">
            <view class="zfbbox">
              <view class="left">
                <image class="img" src="../../static/home/wx.png" mode="aspectFill" />
                <view class="textBox">
                  <view>微信支付</view>
                </view>
              </view>
              <view>
                <radio value="wechat" :checked="'wechat' === formData.withdrawChanel" color="#81d8d0" />
              </view>
            </view>
          </label> -->
          <label class="uni-list-cell uni-list-cell-pd">
            <view class="zfbbox">
              <view class="left">
                <image class="img" src="../../static/shop/zfb.png" mode="aspectFill" />
                <view class="textBox">
                  <view>支付宝支付</view>
                </view>
              </view>
              <view>
                <radio value="alipay" :checked="'alipay' === formData.withdrawChanel" color="#81d8d0" />
              </view>
            </view>
          </label>
        </radio-group>
      </view>
    </view>

    <u-modal :show="showModal" title="提示" showCancelButton @confirm="pay" @cancel="closeFn">
      <view class="popbox" style="width: 100%">
        <u-input v-model="formData.payPassword" placeholder="请输入支付密码" clearable :password="isPass">
          <template #suffix>
            <u-icon name="eye-off" color="#bfbfbf" size="28" v-if="isPass" @click="isPass = false"></u-icon>
            <u-icon name="eye" color="#bfbfbf" size="28" v-else @click="isPass = true"></u-icon>
          </template>
        </u-input>
      </view>
    </u-modal>
    <view class="bottomBox">
      <u-button @click="submit" text="立即提现" shape="circle" color="#81d8d0"></u-button>
    </view>
  </view>
</template>

<script lang="ts" setup>
import { goPage } from "@/utils/commonFn";
import { onMounted, ref } from "vue";

const banlanceAmont = ref("");
const showModal = ref(false);
const payPassword = ref(null);
onMounted(() => {
  getInfo();
});
const radioChange = (evt: any) => {
  formData.value.withdrawChanel = evt.detail.value;
};
const getInfo = async () => {};
const formData = ref({
  amount: "",
  withdrawChanel: "alipay",
  payPassword: "",
  account: "",
});
const isPass = ref(true);
const allClick = () => {
  if (+banlanceAmont === 0) {
    uni.showToast({
      title: "暂无余额",
      icon: "none",
    });
  }
  formData.value.amount = banlanceAmont.value;
};
const submit = () => {
  if (!formData.value.amount) {
    uni.showToast({
      title: "余额不能为0",
      icon: "none",
    });
    return;
  }
  showModal.value = true;
};
const closeFn = () => {
  showModal.value = false;
  payPassword.value = null;
};
const pay = async () => {
  try {
    closeFn();
    getInfo();
    uni.showToast({
      title: "提现成功",
    });
    setTimeout(() => {
      uni.navigateBack();
    }, 300);
  } catch (error: any) {
    if (error.code === 552) {
      closeFn();
      goPage("/pages/myPage/editPage/payPassword");
    }
    if (error.code === 553) {
      closeFn();
      goPage("/pages/myPage/realNameAuth");
    }
    if (error.code === 554) {
      closeFn();
      goPage("/pages/myPage/editPage/zhifubaoPage");
    }
  }
};
</script>

<style lang="less" scoped>
.box {
  border-radius: 32rpx;
  margin-bottom: 20rpx;
  padding: 32rpx 40rpx;
  background: #fff;
  .title {
    font-size: 32rpx;
    font-weight: 600;
    line-height: 44rpx;
    margin-bottom: 20rpx;
  }
  .input_num {
    height: 150rpx;
  }
  .des {
    display: flex;
    justify-content: space-between;
    font-size: 28rpx;
    font-weight: 400;
    color: #bebebe;
  }
  /deep/ .u-cell__body {
    padding-left: 0px;
    padding-right: 0px;
  }
}
.img {
  width: 64rpx;
  height: 64rpx;
}
.payBox {
  padding: 20rpx;
  background: #fff;
  border-radius: 32rpx;
}
.zfbbox {
  display: flex;
  justify-content: space-between;
  margin: 30rpx 0;
  align-items: center;

  .left {
    display: flex;
    align-items: center;
    .img {
      width: 56rpx;
      height: 56rpx;
    }
    .iconBox {
      position: relative;
      margin-right: 14rpx;
      .img,
      .icon {
        width: 38rpx;
        height: 38rpx;
        position: absolute;
        left: 20rpx !important;
        top: 20rpx !important;
      }
      .icon {
        left: 0;
        top: 0;
      }
    }
    .textBox {
      font-size: 30rpx;
      margin-left: 30rpx;
      & > view {
        &:last-child {
          font-size: 24rpx;
        }
      }
    }
  }
}
.all_text {
  font-size: 28rpx;
  font-weight: 400;
  color: #81d8d0;
}
</style>
